import socket
import threading
from collections import deque

class MessageSender(threading.Thread):
	def __init__(self, logger, sock):
		threading.Thread.__init__(self)
		self.logger = logger
		self.sock = sock
		self.queue = deque()

	def add_queue(self, data, address):
		self.queue.append((data, address))

	def add_queue_priority(self, data, address):
		self.queue.appendleft((data, address))

	def run(self):
		while True:
			try:
				data, address = self.queue.popleft()
				self.sock.sendto(data, address)
			except IndexError:
				pass
